package com.application.controller;


import com.application.domain.Leader;
import com.application.service.LeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "操作负责人录入表格")
@RestController
@RequestMapping("/leader")
public class LeaderController {

    @Resource
    LeaderService leaderService;

    @PostMapping
    @ApiOperation(value = "向表格保存数据")
    public Result save(Leader leader){
        int save = leaderService.save(leader);
        String mes = save!=0 ? "保存成功":"保存失败，请重新尝试";
        int code = save !=0 ?Code.SAVE_OK:Code.UPDATE_ERR;
        return new Result(code,save,mes);
    }

    @DeleteMapping
    @ApiOperation(value = "删除表格信息")
    public Result deleteById(@RequestParam String id){
        int deleteById = leaderService.deleteById(id);
        String mes = deleteById!=0 ? "删除成功":"删除失败，请重新尝试";
        int code = deleteById !=0 ?Code.DELETE_OK:Code.DELETE_ERR;
        return new Result(code,deleteById,mes);
    }


    @PutMapping
    @ApiOperation(value = "根据id更新表格数据")
    public Result updateById(@RequestBody Leader leader,@RequestHeader String id){
        int updateById = leaderService.updateById(leader, id);
        String mes = updateById!=0 ? "更新成功":"更新失败，请重新尝试";
        int code = updateById !=0 ?Code.UPDATE_OK:Code.UPDATE_ERR;
        return new Result(code,updateById,mes);
    }


}
